#!/usr/bin/env bash

ENVIRONMENT_TYPE=$1
ENV_DEV="dev"
ENV_DEVTEST="devtest"
ENV_PRODECT="product"
BRIDGE_NET="bert-server-net"
BRIDGE_NET_devtest="bert-server-devtest-net"

# 判断是否传参
if [ ! ${ENVIRONMENT_TYPE} ];then
    echo "请输入是哪个环境,示例：
          开发环境：sh init_bert_server_container.sh dev
          测试环境：sh init_bert_server_container.sh devtest
          线上环境：sh init_bert_server_container.sh product"
    exit 0
fi

######################开发环境###########################
if [ "${ENVIRONMENT_TYPE}" = "$ENV_DEV" ];then
    IMAGE_NAME="bert-server"
    IMAGE_VERSION="v1"
    CONTAINER_NAME="bert_server_dev"
    PORT_MAPPING="8128:8128"            # 主机端口:容器端口


    # 构造镜像
    cd calfdata/faqdata
    
    # docker build -t ${IMAGE_NAME}:${IMAGE_VERSION} .

    # 移除旧的容器
    docker stop ${CONTAINER_NAME}
    docker rm ${CONTAINER_NAME}

    # 实例化容器
    docker run --name ${CONTAINER_NAME} --net=container:nlpservice_dev -d ${IMAGE_NAME}:${IMAGE_VERSION}
    #docker run -it --name centos-1 --network testnet --network-alias centos-1 docker.io/centos:latest


    exit 0
fi
######################开发环境###########################

######################测试环境###########################
if [ "${ENVIRONMENT_TYPE}" = "$ENV_DEVTEST" ];then
    IMAGE_NAME="bert-server"
    IMAGE_VERSION="v1"
    CONTAINER_NAME="bert_server_devtest"
    BUILD_CONTEXT_PAHT="calfdata/faqdata"
    BERT_PORT_IN="5555:5555"
    BERT_POST_OUT="5556:5556"
    # 构造镜像
    cd calfdata/faqdata

    # 构造镜像
    #docker build -t ${IMAGE_NAME}:${IMAGE_VERSION} .

    # 移除旧的容器
     docker stop ${CONTAINER_NAME}
     docker rm ${CONTAINER_NAME}

    # 实例化容器
    docker run --name ${CONTAINER_NAME} --network ${BRIDGE_NET_devtest} -d ${IMAGE_NAME}:${IMAGE_VERSION}

    exit 0
fi

######################线上环境###########################
if [ "${ENVIRONMENT_TYPE}" = "$ENV_PRODECT" ];then
    IMAGE_NAME="bert-server"
    IMAGE_VERSION="v1"
    CONTAINER_NAME="bert_server"
    BUILD_CONTEXT_PAHT="calfdata/faqdata"

    # 构造镜像
    cd calfdata/faqdata

    # 构造镜像
    docker build -t ${IMAGE_NAME}:${IMAGE_VERSION} .

    # 移除旧的容器
    # docker stop ${CONTAINER_NAME}
    # docker rm ${CONTAINER_NAME}

    # 实例化容器
#    docker run --name ${CONTAINER_NAME} -d ${IMAGE_NAME}:${IMAGE_VERSION}
    docker run --name ${CONTAINER_NAME}  --network ${BRIDGE_NET} -d ${IMAGE_NAME}:${IMAGE_VERSION}

    exit 0
fi
######################线上环境###########################

echo "ENVIRONMENT_TYPE Error!!!!"